package com.iamsleeping;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Mohit on 05-Apr-14.
 */
public class Settings {
    Boolean b_appStatus;
    Boolean b_autoCutCalls;
    Boolean b_doNotDisturb;
    Boolean b_setAlarm;
    String s_msgText;
    SharedPreferences prefs;
    private static Settings mySettings;

    public static Settings getInstance(Context context) {
        if (mySettings == null) {
            mySettings = new Settings(context);
        }
        return mySettings;
    }

    private Settings(Context context) {
        prefs = context.getSharedPreferences("com.iamsleeping", Context.MODE_PRIVATE);
        b_doNotDisturb = prefs.getBoolean(Constants.DO_NOT_DISTURB, false);
        b_setAlarm = prefs.getBoolean(Constants.SET_ALARM, false);
        b_autoCutCalls = prefs.getBoolean(Constants.AUTO_CUT_CALLS, false);
        b_appStatus = prefs.getBoolean(Constants.APP_STATUS, false);
        s_msgText = prefs.getString(Constants.MSG_TEXT, "Please call me back later");
    }

    public void setAppStatus(Boolean b_appStatus) {
        this.b_appStatus = b_appStatus;
        prefs.edit().putBoolean(Constants.APP_STATUS, b_appStatus).commit();

    }

    public void setAlarmOn(Boolean b_setAlarm) {
        this.b_setAlarm = b_setAlarm;
        prefs.edit().putBoolean(Constants.SET_ALARM, b_setAlarm).commit();

    }
    public void setAutoCutCalls(Boolean b_autoCutCalls) {
        this.b_autoCutCalls = b_autoCutCalls;
        prefs.edit().putBoolean(Constants.AUTO_CUT_CALLS, b_autoCutCalls).commit();
    }

    public void setDoNotDisturb(Boolean b_doNotDisturb) {
        this.b_doNotDisturb = b_doNotDisturb;
        prefs.edit().putBoolean(Constants.DO_NOT_DISTURB, b_appStatus).commit();
    }

    public void setMsgText(String s_msgText) {
        this.s_msgText = s_msgText;
        prefs.edit().putString(Constants.MSG_TEXT, s_msgText).commit();
    }

    public Boolean getAppStatus() {
        return b_appStatus;
    }

    public Boolean getAutoCutCalls() {
        return b_autoCutCalls;
    }

    public Boolean getDoNotDisturb() {
        return b_doNotDisturb;
    }

    public String getMsgText() {
        return s_msgText;
    }

    public void toggleAppStatus() {
        setAppStatus(!b_appStatus);
    }

    public void toggleDoNotDisturb() {
        setDoNotDisturb(!b_doNotDisturb);
    }

    public void toggleAutoCutCalls() {
        setAutoCutCalls(!b_autoCutCalls);
    }

    public Boolean getSetAlarm() {
        return b_setAlarm;
    }

    public void toggleSetAlarm() {
        setAlarmOn(!b_setAlarm);
    }

}
